import Taro, { Component } from '@tarojs/taro'
import { AtButton } from 'taro-ui'
import classnames from 'classnames'
import PropsType from 'prop-types'
import { View, Text, Image } from '@tarojs/components'
import '../styles/carship.scss'

const carIcon = require('../assete/icon_car.png')

export default class DCarship extends Component {

    onHandleDetail() {
        this.props.onHandleDetail && this.props.onHandleDetail()
    }

    onHandleFirst(e) {
        e.stopPropagation()
        this.props.onHandleFirst && this.props.onHandleFirst()
    }
    onHandleLast(e) {
        e.stopPropagation()
        this.props.onHandleLast && this.props.onHandleLast()
    }
    render() {
        const {
            className,
            order,
            status,
            card,
            data,
            beginaddre,
            endaddre,
            addre,
            money,
            firstText,
            lastText,
        } = this.props
        return (
            <View className={classnames('b_carship', className)} onClick={this.onHandleDetail.bind(this)}>
                <View className='b_carship__munber'>
                    <View className='b_carship__munber_left'>
                        <Text className='b_carship__munber_text'>运</Text>
                        <Text className='b_carship__munber_item'>{order}</Text>
                    </View>
                    <View className='b_carship__munber_status'>{status}</View>
                </View>
                <View className='b_carship__title'>
                    <Image src={carIcon} className='b_carship__title_icon'></Image>
                    <View className='b_carship__title_content'>
                        <Text className='b_carship__itemtitle' >{card}</Text>
                    </View>
                </View>
                <View className='b_carship__addre'>{addre}</View>
                <View className='b_carship__addre'>运输日期：{data}</View>
                <View className='b_carship__addre'>始发地：{beginaddre}</View>
                <View className='b_carship__addre'>目的地：{endaddre}</View>
                <View className='b_carship__footer'>
                    <View className='b_carship__footer_left'>
                        <Text className='b_carship__footer_left__total'>运输费</Text>
                        <Text className='b_carship__footer_left__money'>￥{money}元</Text>
                    </View>
                    {
                        firstText && <AtButton onClick={this.onHandleFirst.bind(this)}>{firstText}</AtButton>

                    }
                    {
                        lastText && <AtButton onClick={this.onHandleLast.bind(this)}>{lastText}</AtButton>
                    }
                </View>
            </View>
        )
    }
}

DCarship.defaultProps = {
    className: '',
    order: ' YS20191114001',
    status: '待审核',
    card: '粤A12345',
    data: '2019年10月07日',
    addre: '广东一二三有限公司',
    beginaddre: '广东省广州市天河区员村一横路',
    endaddre: '广东省广州市天河区员村一横路',
    money: '350',
    firstText: '',
    lastText: '',
    onHandleDetail: () => { },
    onHandleFirst: () => { },
    onHandleLast: () => { }
}

DCarship.PropsType = {
    className: PropsType.oneOfType[PropsType.string, PropsType.object],
    order: PropsType.string,
    status: PropsType.string,
    card: PropsType.string,
    data: PropsType.string,
    flag: PropsType.array,
    tipmoney: PropsType.string,
    addre: PropsType.string,
    money: PropsType.string,
    firstText: PropsType.string,
    onHandleDetail: PropsType.func,
    onHandleFirst: PropsType.func,
    onHandleLast: PropsType.func
}